package name.wilbur.course.db.bigone.service.impl;

import name.wilbur.course.db.bigone.dao.DAOFactory;
import name.wilbur.course.db.bigone.dao.impl.IProfileDAO;
import name.wilbur.course.db.bigone.dao.impl.IUserProfileViewDAO;
import name.wilbur.course.db.bigone.dao.impl.ProfileDAO;
import name.wilbur.course.db.bigone.dao.impl.UserProfileViewDAO;
import name.wilbur.course.db.bigone.model.Profile;
import name.wilbur.course.db.bigone.model.UserProfileView;
import name.wilbur.course.db.bigone.service.ISearchService;

public class SearchService implements ISearchService {
	private IProfileDAO profileDAO;
	private IUserProfileViewDAO userProfileViewDAO;
	
	public SearchService() {
	}

	public UserProfileView[] searchWithNameCityView(String name, String cityName) {
		return getUserProfileViewDAO().findByNameAndCity(name, cityName);
	}
	
	public Profile[] searchWithNameCity(String name, int cityID) {
		return getProfileDAO().findByNameAndCity(name, cityID);
	}
	
	public IUserProfileViewDAO getUserProfileViewDAO() {
		if (userProfileViewDAO == null)
			userProfileViewDAO = (UserProfileViewDAO) DAOFactory.createDAO(UserProfileViewDAO.class);
		return userProfileViewDAO;
	}
	
	public IProfileDAO getProfileDAO() {
		if (profileDAO == null)
			profileDAO = (ProfileDAO) DAOFactory.createDAO(ProfileDAO.class);
		return profileDAO;
	}
}
